package com.hefei.hight.proxy.base;

import java.lang.reflect.Proxy;

/**
 * @author caizhengjun
 * @date 2020/9/5 2:42 下午
 */
public class ProxyFactory {

    private Object target;

    public ProxyFactory(Object target) {
        this.target = target;
    }

    public Object getProxyInstance() {
        return Proxy.newProxyInstance(target.getClass().getClassLoader(), target.getClass().getInterfaces(), (proxy, method, args) -> {

            //System.out.println("proxy = " + proxy);

            System.out.println("开启事务");
            method.invoke(target, args);
            System.out.println("提交事务");
            return null;
        });
    }
}
